package com.neuedu.ExceptionDemo01;

public class Account {
    /**
     * 私有化变量账户
     */
    private String account;
    /**
     * 私有化变量账户余额
     */
    private double balance;

    /**
     * Account的空参构造
     */
    public Account() {
    }

    /**
     * Account的全参构造
     * @param account 初始化账户账号
     * @param balance 初始化账户余额
     */
    public Account(String account, double balance) {
        this.account = account;
        this.balance = balance;
    }

    /**
     * 为私有化变量account和balance创建get和set方法
     */
    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    /**
     * 创建存钱方法
     * @param d 用户存入账户的钱
     * @return 用户存入钱后账户内的余额
     */
    public double save(double d){
        double result=balance+d;
        System.out.println("余额为: "+result);
        return result;
    }

    /**
     * 创建取钱方法
     * @param d 用户取出的钱
     * @return 用户取出钱后账户内的余额
     * @throws BNEException 若用户所输入取出的钱大于余额时所报异常
     */
    public double pay(double d)throws BNEException {
        double result=balance-d;
        if (result<0){
            throw new BNEException();
        }
        System.out.println("余额为: "+result);
        return result;
    }
}
